import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 将员工集合传入，将员工信息添加到员工集合中
 */
public class Add {
    public static <T> void add(List<T> em, String instruction)  {


        Scanner scanner = new Scanner(System.in);
        //员工信息
        TreeMap<String, Object> employee = new TreeMap<>();

        while (true) {
            System.out.print("请输入员工编号：");
            String id = scanner.nextLine();
            if (Id.isId(em, id)) {
                System.out.println("编号已存在，请重新输入");
                continue;
            }
            try {
                employee.put("id", Integer.parseInt(id));
                break;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("编号输入错误，请重新输入");
            }
        }

        System.out.print("请输入员工姓名：");
        String name = scanner.nextLine();
        employee.put("name", name);

        while (true) {
            System.out.print("请输入员工年龄：");
            String age = scanner.nextLine();
            try {
                employee.put("age", Integer.parseInt(age));
                break;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("年龄输入错误，请重新输入");
            }
        }

        System.out.print("请输入员工职位：");
        String job = scanner.nextLine();
        employee.put("job", job);

        while (true) {
            System.out.print("请输入员工工资：");
            String salary = scanner.nextLine();
            try {
                employee.put("salary", Double.parseDouble(salary));
                break;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("员工工资输入错误，请重新输入");
            }
        }

        while (true) {
            System.out.print("请输入员工入职时间（格式：yyyy-MM-dd）：");
            String str = scanner.nextLine();
            try {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                employee.put("time", str);
                break;
            } catch (Exception e) {
                System.out.println("日期格式错误，请使用yyyy-MM-dd格式");
                e.printStackTrace();
            }
        }
        em.add((T) employee);
        System.out.println("-----员工信息表-----");
        for (T t : em) {
            System.out.println(t);
        }
        System.out.println("-------------------");
    }

}
